def generate_triangle(n):
    triangle = []
    for i in range(n):
        row = [1]
        for j in range(1, i):
            row.append(triangle[i-1][j-1] + triangle[i-1][j])
        if i != 0:
            row.append(1)
        triangle.append(row)
    return triangle
def print_triangle(triangle):
    n = len(triangle)
    width = len(str(triangle[-1][-1]))
    for i in range(n):
        row = ''
        for j in range(i+1):
            row += str(triangle[i][j]).rjust(width, ' ') + ' '
        print(row.center(width*n, ' '))
n = int(input('请输入要打印的行数: '))
triangle = generate_triangle(n)
print_triangle(triangle)



# 这个函数根据用户指定的行数打印出一个三角形。
# 首先，通过循环遍历给定的行数并将三角形的每一行附加到列表中来生成三角形。
# 第二个函数以格式化的方式打印出生成的三角形。此代码用于打印outPascal的三角形。

import sys
n = int(input())
t = 1
# n为1直接出结果
if n == 1:
    print(1)
    sys.exit()

# 先找到是哪一列比较接近
l = 0  # 行
r = 0  # 列
while t < n:
    t = 1
    l += 2
    r += 1
    for i in range(l - r + 1, l + 1):  # 排列组合求杨辉三角
        t *= i
    for i in range(2, r + 1):
        t //= i
##        print(t)

if t == n:
    print(l * (l + 1) // 2 + r + 1)
    sys.exit()
else:
    l -= 2
    r -= 1
    t = 1

# 再用二分法在竖列中查找
j = l
k = n
while t != n:
    l = (j + k) // 2
    t = 1
    for i in range(l - r + 1, l + 1):  # 排列组合求杨辉三角
        t *= i
    for i in range(2, r + 1):
        t //= i
    if j < k:  # 二分查找
        if t > n:
            k = l - 1
        elif t < n:
            j = l + 1
    elif t == n:  # 找到就退出，以免坐标错乱
        break;
    else:  # 这里是该列找不到，就往前一列找
        r -= 1
        k = n
##        print(t)

print(l * (l + 1) // 2 + r + 1)  # 利用坐标求位置


def find_in_pascals_triangle(n):
    """
    Given a number n, find it in the Pascal's Triangle using binary search.
    Returns a tuple (row, col) representing the index of the number in the triangle.
    Returns None if the number is not found in the triangle.
    给定一个数字 n，使用二进制搜索在帕斯卡三角形中找到它。
    返回一个元组（行、列），表示三角形中数字的索引。如果在三角形中找不到该数字，则返回 None。
    """
    i = 0
    # Number of columns in each row of Pascal's Triangle is equal to the row number itself.
    # 帕斯卡三角形每行中的列数等于行号本身。
    j = i
    while i <= j:
        mid = (i + j) // 2
        num = binomial_coefficient(mid, i)
        if num == n:
            return (mid, i)
        elif num < n:
            i = mid + 1
        else:
            j = mid - 1
    return None
def binomial_coefficient(n, k):
    """
    Compute the binomial coefficient (n choose k) using the formula n!/(k!*(n-k)!).
    """
    if k > n:
        return 0
    if k == 0 or k == n:
        return 1
    # Compute n!/(k!*(n-k)!) using iterative multiplication.
    # This is more efficient than computing n!/(k!*(n-k)!) directly.
    result = 1
    for i in range(1, min(k, n - k) + 1):
        result *= n - i + 1
        result //= i
    return result